﻿#pragma once

#include "pyverifycore_global.h"
#include "licenseadministrator_global.h"
#include <QByteArray>
#include <QDateTime>

#ifdef LICENSEADMINISTRATOR_LIB 
#define LIBRARY_EXPORT LICENSEADMINISTRATOR_EXPORT
#endif

#ifdef PYVERIFYCORE_LIB
#define LIBRARY_EXPORT PYVERIFYCORE_EXPORT
#endif

#ifndef LIBRARY_EXPORT
#define LIBRARY_EXPORT
#endif

typedef struct rsa_st RSA;
class QDatetime;

struct License {
	QByteArray freetime;		//第一次启动时间
	QByteArray id;				//UUID
	QByteArray targetTime;		//永久时间或者免费时间
};

struct  SignLicense {
	QByteArray lic;
	QByteArray sign;
};

class LIBRARY_EXPORT SystemInfoForLicense {
public:
	virtual ~SystemInfoForLicense() = default;
	virtual QByteArray getCpuSerialNum() = 0;
	virtual QByteArray getUuid() = 0;
	virtual QString filePath() = 0;
	virtual std::tuple<License, QByteArray, QByteArray> parse_keyfile(bool isLicFileOnly) = 0;
};

class LIBRARY_EXPORT LicenseVerify :public SystemInfoForLicense {
public:
	virtual ~LicenseVerify() = default;
	virtual bool checkTimeout(bool licFileOnly = false) = 0;
	virtual void writFirst() = 0;
protected:
	//type = 0公钥 1=私钥
	virtual RSA* extractRsa(const uint8_t* key) = 0;
	virtual QByteArray encryTime(QDateTime datetime = QDateTime(), QByteArray const&& serialNum = std::move(QByteArray())) = 0;
	friend class LicenseAdministratorImp;
};

class LIBRARY_EXPORT LicenseSign {
public:
	~LicenseSign() = default;
	virtual void writeDateLic(QDateTime datetime) = 0;
};

class LIBRARY_EXPORT LicenseAdministrator : protected LicenseVerify, public LicenseSign {
public:
	virtual ~LicenseAdministrator() = default;
	virtual void setMask(QByteArray const&& maskNum) = 0;
	virtual void setProgramUuid(QByteArray const&& puid) = 0;
	virtual QByteArray generateLicenseKeys(QDateTime targetDate) = 0;
	virtual void setOutPath(QString const&& filePaht) = 0;
	virtual void generateLicenseFile(QString const&& execFilePath, QDateTime targetTime) = 0;
};

extern "C" {
	extern LIBRARY_EXPORT LicenseVerify* make_verify_interface();
}